// Copyright (c) 2009-2019 The Regents of the University of Michigan
// This file is part of the HOOMD-blue project, released under the BSD 3-Clause License.


// Maintainer: mphoward

#ifndef __NEIGHBORLOSTGPUSTENCIL_CUH__
#define __NEIGHBORLOSTGPUSTENCIL_CUH__

#include <cuda_runtime.h>

#include "hoomd/HOOMDMath.h"
#include "hoomd/Index1D.h"
#include "hoomd/ParticleData.cuh"

/*! \file NeighborListGPUStencil.cuh
    \brief Declares GPU kernel code for neighbor list generation on the GPU
*/

#define WARP_SIZE 32
const unsigned int min_threads_per_particle=1;
const unsigned int max_threads_per_particle=WARP_SIZE;

//! Kernel driver for gpu_compute_nlist_multi_binned_kernel()
cudaError_t gpu_compute_nlist_stencil(unsigned int *d_nlist,
                                      unsigned int *d_n_neigh,
                                      Scalar4 *d_last_updated_pos,
                                      unsigned int *d_conditions,
                                      const unsigned int *d_Nmax,
                                      const unsigned int *d_head_list,
                                      const unsigned int *d_pid_map,
                                      const Scalar4 *d_pos,
                                      const unsigned int *d_body,
                                      const Scalar *d_diameter,
                                      const unsigned int N,
                                      const unsigned int *d_cell_size,
                                      const Scalar4 *d_cell_xyzf,
                                      const Scalar4 *d_cell_tdb,
                                      const Index3D& ci,
                                      const Index2D& cli,
                                      const Scalar4 *d_stencil,
                                      const unsigned int *d_n_stencil,
                                      const Index2D& stencil_idx,
                                      const BoxDim& box,
                                      const Scalar *d_r_cut,
                                      const Scalar r_buff,
                                      const unsigned int ntypes,
                                      const Scalar3& ghost_width,
                                      bool filter_body,
                                      bool diameter_shift,
                                      const unsigned int threads_per_particle,
                                      const unsigned int block_size);

//! Kernel driver for filling the particle types for sorting
cudaError_t gpu_compute_nlist_stencil_fill_types(unsigned int *d_pids,
                                                 unsigned int *d_types,
                                                 const Scalar4 *d_pos,
                                                 const unsigned int N);

//! Wrapper to CUB sorting
void gpu_compute_nlist_stencil_sort_types(unsigned int *d_pids,
                                          unsigned int *d_pids_alt,
                                          unsigned int *d_types,
                                          unsigned int *d_types_alt,
                                          void *d_tmp_storage,
                                          size_t &tmp_storage_bytes,
                                          bool &swap,
                                          const unsigned int N);
#endif // __NEIGHBORLOSTGPUSTENCIL_CUH__
